package com.llc.mall.leaf;

import io.seata.spring.boot.autoconfigure.SeataAutoConfiguration;
import io.seata.spring.boot.autoconfigure.SeataDataSourceAutoConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.event.ApplicationStartingEvent;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ApplicationListener;

/**
 * @author 
 */
@SpringBootApplication(
		scanBasePackages = {"com.mall4j.cloud", "com.llc.mall"},
		exclude = {
				SeataAutoConfiguration.class,
				SeataDataSourceAutoConfiguration.class
		}
)
@EnableFeignClients(basePackages = {"com.mall4j.cloud.api.**.feign"})
public class LeafApplication {

	private static final Logger log = LoggerFactory.getLogger(LeafApplication.class);

	private static volatile long startTime;

	public static void main(String[] args) {
		SpringApplication app = new SpringApplication(LeafApplication.class);
		// 添加启动开始事件监听
		app.addListeners((ApplicationListener<ApplicationStartingEvent>) event ->
				startTime = System.currentTimeMillis()
		);
		// 添加启动完成事件监听
		app.addListeners((ApplicationListener<ApplicationReadyEvent>) event -> {
			long cost = System.currentTimeMillis() - startTime;
			log.info("======> Leaf服务启动完成, 耗时: {} ms <====== ", cost);
		});
		app.run(args);
	}

}
